<template>
    <div id="barMain"></div>
</template>

<script lang='ts' setup>
import { reactive, ref, onBeforeMount, onMounted } from 'vue'
import * as echarts from 'echarts';
import { useCommon } from '@/hooks/web/useCommon'
type EChartsOption = echarts.EChartsOption;
var option: EChartsOption;
const { throttle, createFigure, chartRef } = useCommon()
onMounted(() => {
    chartRef.value = 'barMain'
    window.addEventListener("resize", throttle(createFigure, 500));
    getChartsData()
})


const getChartsData = () => {
    var chartDom = document.getElementById('barMain')!;
    var myChart = echarts.init(chartDom, 'light');
    var xData = function () {
        return ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"];
    }();
    option = {

        "title": {
            "text": "本周报名人数统计",
            'left': 'center'
        },
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "shadow",
                textStyle: {
                    color: "#fff"
                }

            },
        },
        "grid": {
            "borderWidth": 0,
            "top": "15%",
            "bottom": '10%',
            textStyle: {
                color: "#fff"
            }
        },
        "legend": {
            x: '4%',
            top: '8%',
            textStyle: {
                color: '#90979c',
            },
            "data": ['女', '男', '平均']
        },


        "calculable": true,
        "xAxis": [{
            "type": "category",
            "axisLine": {
                lineStyle: {
                    color: '#90979c'
                }
            },
            "splitLine": {
                "show": false
            },
            "axisTick": {
                "show": false
            },
            "splitArea": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,

            },
            "data": xData,
        }],
        "yAxis": [{
            "type": "value",
            "splitLine": {
                "show": false
            },

            "axisTick": {
                "show": false
            },
            "axisLabel": {
                "interval": 0,

            },
            "splitArea": {
                "show": false
            },

        }],

        "series": [{
            "name": "孔德坤",
            "type": "bar",
            "stack": "总量",
            "barMaxWidth": 35,
            "barGap": "10%",
            "itemStyle": {
                "normal": {
                    "label": {
                        "show": true,
                        "textStyle": {
                            "color": "#fff"
                        },
                        "position": "inside",
                        formatter: function (p) {
                            return p.value > 0 ? (p.value) : '';
                        }
                    }
                }
            },
            "data": [
                709,
                1917,
                2455,
                2610,
                1719,
                1433,
                1544,
            ],
        },

        {
            "name": "王丽",
            "type": "bar",
            "stack": "总量",
            "itemStyle": {
                "normal": {

                    "barBorderRadius": 0,
                    "label": {
                        "show": true,
                        "position": "inside",
                        formatter: function (p) {
                            return p.value > 0 ? (p.value) : '';
                        }
                    }
                }
            },
            "data": [
                327,
                1776,
                507,
                1200,
                800,
                482,
                204,

            ]
        }, {
            "name": "总数",
            "type": "line",
            symbolSize: 10,
            symbol: 'circle',
            "itemStyle": {
                "normal": {
                    "color": "rgba(252,230,48,1)",
                    "barBorderRadius": 0,
                    "label": {
                        "show": true,
                        "position": "top",
                        formatter: function (p) {
                            return p.value > 0 ? (p.value) : '';
                        }
                    }
                }
            },
            "data": [
                1036,
                3693,
                2962,
                3810,
                2519,
                1915,
                1748,

            ]
        },
        ]
    }

    option && myChart.setOption(option);

}

</script>
<style scoped>
#barMain {
    width: 100%;
    height: 300px;
}
</style>